// 封装个人信息相关的请求异步函数
import { ApiRes, User, UserProfile } from "@/types/data"
import { RootAction, RootThunkAction } from "@/types/store"
import http from "@/utils/request"

// 获取用户基本信息
export const getUser = (): RootThunkAction => {
    return async(dispatch) => {
        const res = await http.get<ApiRes<User>>('/user')
        console.log(res)
         // 存储到仓库
         dispatch({
            type: 'profile/set_user',
            payload: res.data.data
        } as RootAction)
    } 
}

// 获取用户详情
export const getUserDetail = (): RootThunkAction => {
    return async(dispatch) => {
        const res = await http.get<ApiRes<UserProfile>>('/user/profile')
        console.log(res)
         // 存储到仓库
         dispatch({
            type: 'profile/set_user_profile',
            payload: res.data.data
        } as RootAction)
    } 
}

